package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.sgb.kjwl.R;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.link.view.adapter.PickAdapter;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import java.util.List;
import com.swgk.core.dialog.BasePopWindow;
/**
 * Created by：冯齐 on 2021/1/24 10:02
 * Description：工队列表PopWindow
 */
public class ConstructionTeamPPW extends BasePopWindow {

    private RecyclerView recyclerView;
    private PickAdapter pickAdapterCity;
    private List<PickSelectEntity> cityDatas;
    private String no = "";
    private String name = "";
    private int mPosition = -1;
    private LinearLayout rootlayout;
    private View coverlayout;

    public ConstructionTeamPPW(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_area_two;
    }


    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.rlv_list);
        rootlayout = holder.getPop().findViewById(R.id.root_layout);
        coverlayout = holder.getPop().findViewById(R.id.cover_layout);
        coverlayout.setVisibility(View.VISIBLE);
        rootlayout.setPadding(0,0,0,0);
      //  recyclerView.setBackgroundColor(mContext.getResources().getColor(R.color.white));item_construction_team
        pickAdapterCity = new PickAdapter(mContext, null, R.layout.item_pick_filter_child_5);
    //    pickAdapterCity = new PickAdapter(mContext, null, R.layout.item_construction_team);
        pickAdapterCity.setItemSelect(true);
        pickAdapterCity.setDefItem(0);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(pickAdapterCity);
        pickAdapterCity.setOnItemClick(new AdapterOnItemClick<PickSelectEntity>() {
            @Override
            public void onItemClick(PickSelectEntity pickSelectEntity, int position) {
                no = pickSelectEntity.getNo();
                name = pickSelectEntity.getProjectscale();
                mPosition = position;
                if (onResultClick != null) {
                    onResultClick.result(no, name, position);
                    //Log.d("城市编号", no);
                }
                dissMiss();
            }
        });
    }

    public void setData(List<PickSelectEntity> cityDatas) {
        this.cityDatas = cityDatas;
        pickAdapterCity.setDatas(cityDatas);
    }

    public void setData(List<PickSelectEntity> cityDatas, int position) {
        mPosition = position;
        this.cityDatas = cityDatas;
        pickAdapterCity.setDatas(cityDatas);
        pickAdapterCity.setDefItem(position);
    }

    public void setVisibleList(boolean visible) {
        recyclerView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
    }

    public void setDefData(int position) {
        pickAdapterCity.setDefItem(position);
    }

    public int getPosition() {
        return mPosition;
    }

    public List<PickSelectEntity> getData() {
        return pickAdapterCity.getDatas();
    }

    public PickSelectEntity getResult() {
        if (mPosition == -1) {
            return null;
        }
        return pickAdapterCity.getDatas().get(mPosition);
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (onDisMiss != null)
            onDisMiss.disMiss();
    }
}
